package middle;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution_17 {

    private char[][] temp = {{'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'},
        {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}};

    public List<String> letterCombinations(String digits) {
        if (digits.length() == 0) return new ArrayList<>();
        Set<String> set = new HashSet<>();
        dps(set, new char[digits.length()], digits.toCharArray(), 0);
        return new ArrayList<>(set);
    }

    private void dps(Set<String> set, char[] res, char[] chars, int index) {
        if (chars.length == index) {
            set.add(new String(res));
            return;
        }
        int num = chars[index] - '0' - 2;
        for (char c : temp[num]) {
            res[index] = c;
            dps(set, res, chars, index + 1);
        }
    }

    public static void main(String[] args) {
        Solution_17 model = new Solution_17();
        System.out.println(model.letterCombinations("23"));
        System.out.println(model.letterCombinations(""));
        System.out.println(model.letterCombinations("2"));
    }
}
